
var username = huoqucookie('username')
if (username) {
    document.querySelector('.headr_right').innerHTML = '<div class="zuo"><a href="login.html">'+ username+'</a></div><div class="zhon">|</div><div class="you">退出</div>'
    document.querySelector('.you').onclick = function () {
        if (confirm("你确定要残忍离开吗？")) {
            removeCookie('username')
            document.querySelector('.headr_right').innerHTML = `
            <div class="zuo"><a href="denlu.html">登录</a></div>
            <div class="zhon">|</div>
            <div class="you"><a href="zhuche.html">注册</a></div>
            <img src="./images/小手机.png" alt="">
        `;
        }
    }
}


function huoqucookie(key) {
    var cookies = document.cookie;
    var arr = cookies.split("; ")
    for (var i = 0; i < arr.length; i++) {
        var brr = arr[i].split('=')
        if (brr[0] === key) {
            return brr[1]
        }
    }
}
function shezhicookie(key, value, seconds, path = '/') {
    var date = new Date()
    date.setTime(date.getTime() + seconds * 1000 - 8 * 3600 * 1000)
    document.cookie = `${key}=${value};expires=${date};path=${path}`
}
function removeCookie(key, path = "/") {
    shezhicookie(key, null, -20, path)
}
